---
# Configuration for MirrorManager's crawler

- name: clean yum metadata
  command: yum clean all
  tags:
  - packages

- name: install needed packages
  yum: pkg={{ item }} state=present
  with_items:
  - mirrormanager2-crawler
  - python-psycopg2
  - fedmsg
  - python-GeoIP
  tags:
  - packages

- name: create /etc/mirrormanager
  file: path=/etc/mirrormanager state=directory

- name: install MM configuration file
  template: src={{ item.file }} dest={{ item.dest }}
              owner=mirrormanager group=mirrormanager mode=0600
  with_items:
  - { file: "{{ roles }}/mirrormanager/frontend2/templates/mirrormanager2.cfg",
      dest: /etc/mirrormanager/mirrormanager2.cfg }
  - { file: "{{ roles }}/mirrormanager/frontend2/templates/alembic.ini",
      dest: /etc/mirrormanager/alembic.ini }
  tags:
  - config

- name: install the cron job
  copy: src=crawler.cron dest=/etc/cron.d/mm2_crawler.cron
  tags:
  - config
  when: env != 'staging'

- name: install the script to distribute the mirrors to crawl
  copy: src=mm2_get-mirrors-to-crawl dest=/usr/local/bin/mm2_get-mirrors-to-crawl mode=0755

- name: install the crawler distribute script
  copy: src=run_crawler.sh dest=/usr/local/bin/run_crawler.sh mode=0755

# Directory used to store the result of the repomd.xml propagation test
- name: create /var/log/mirrormanager/propagation
  file: path=/var/log/mirrormanager/propagation state=directory
          owner=mirrormanager group=mirrormanager mode=0755

- name: propagation cronjob rawhide
  cron: name="propagation-rawhide" minute="45" hour="*/2" user="mirrormanager"
        job="/usr/bin/mm2_crawler --propagation --threads 50 2>&1 | grep SHA256 > /var/log/mirrormanager/propagation/propagation.log.$( date +\%s )"
        cron_file=propagation-rawhide
  when: inventory_hostname.startswith('mm-crawler01')

- name: propagation cronjob f22-updates
  cron: name="propagation-f22-updates" minute="15" hour="*/2" user="mirrormanager"
        job="/usr/bin/mm2_crawler --propagation --threads 50 --proppath updates/22/x86_64/repodata 2>&1 | grep SHA256 > /var/log/mirrormanager/propagation/f22-updates-propagation.log.$( date +\%s )"
        cron_file=propagation-f22-updates
  when: inventory_hostname.startswith('mm-crawler01')
